import parse from '@dfeidao/atom-web/dt/parse';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
export default async function a005(fd: IFeidaoAiBrowserComponent) {
	const training_name = fd.data.node.querySelector<HTMLInputElement>('[name="input1"]').value;
	const lecturer_number = get(fd, 'lecturer_number');
	const lecturer_name = get(fd, 'lecturer_name');
	console.log(lecturer_number);
	console.log(lecturer_name);

	const c = fd.data.node.querySelector<HTMLInputElement>('[name="input3"]').value;
	const d = fd.data.node.querySelector<HTMLInputElement>('[name="input4"]').value;
	const training_location = fd.data.node.querySelector<HTMLInputElement>('[name="input5"]').value;
	const training_content = fd.data.node.querySelector<HTMLInputElement>('[name="input6"]').value;
	const train_start_time = parse(c);
	const training_time = parse(d);

	console.log(train_start_time + '------------' + training_time);
	const a003 = fd.data.node.querySelector<HTMLDivElement>('[data-div="add"]');

	if (!a003 || !training_name || !lecturer_number || !lecturer_name || !train_start_time || !training_time || !training_location || !training_content) {
		alert("请填写完整信息");
	} else if (train_start_time > training_time) {
		alert('培训时间出错');
	} else {
		console.log('正确');
		const res = await nodejs<{ code: number, result: string }>('train-plan/zj-000003/s002', {
			training_name,
			lecturer_number,
			lecturer_name,
			train_start_time,
			training_time,
			training_location,
			training_content,
			to_state: 100,
			take_effect: 0,
			supposed_come_peo_num: 10,
			attendance: 1,
			training_conclusion: '完美'
		});

		// const res1 = await nodejs('', {

		// });
		const train_number = res.result;
		console.log(train_number + '-00--------');
		const ids = get(fd, 'id1');
		const names = get(fd, 'name1');
		console.log(ids);

		const res1 = await nodejs<{ code: number }>('train-plan/zj-000003/s003', {
			train_number,
			safety_department_no: ids[0],
			safety_department_name: names[0]


		}); console.log(res1);
		const name_training_material = get(fd, 'titlename');
		const address_training_material = get(fd, 'title');
		const ress = await nodejs<{ code: number }>('train-plan/zj-000003/s004', {
			train_number,
			name_training_material,
			address_training_material
		});
		console.log(res.code);
		console.log(res1.code);
		console.log(ress.code);
		if (res.code === 1 && res1.code === 1 && ress.code === 1) {
			alert("新增成功");
			window.location.reload();
		}
	}


}
